<%@ page import="com.sun.tools.javac.resources.javac" %>
<%@ page import="java.util.Date" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>

<h1 class="page-title">账号设置</h1>

<table class="display" id="example">
    <thead>
    <tr>
        <th>选择</th>
        <th>员工工号</th>
        <th>姓名</th>
        <th>部门</th>
        <th>职务</th>
        <th>登录名称</th>
        <th>最后登录时间</th>
    </tr>
    </thead>
    <tbody>
    <s:if test="#request.users==null || #request.users.size==0">
        <tr class="gradeX">
            <td colspan="7">暂无数据</td>
        </tr>
    </s:if>
    <s:iterator value="#request.users" var="user" status="sta">
        <s:if test="#request.sta.odd">
            <tr class="gradeC">
        </s:if>
        <s:else>
            <tr class="gradeA">
        </s:else>
        <td><input type="checkbox" name="check_user" value="${user.id}"/></td>
        <td><a href="#employee/staff_view.xhtml?id=${user.work.id}">${user.work.workNo}</a></td>
        <td>${user.work.baseId.name}</td>
        <td>${user.work.organization.fullName}</td>
        <td>${user.work.duty.dutyName}</td>
        <td>${user.loginName}</td>
        <td><s:date name="#user.loginTime" format="yyyy-MM-dd hh:mm"/></td>
        </tr>
    </s:iterator>
    </tbody>
</table>
<p>
    <%@ include file="/WEB-INF/pages/common/main_orgtab_pager.jsp" %>
</p>

<div class="tabs side grid_12 leading">
    <div class="clear"></div>
    <div class="grid_12">
        <div class="form-action clearfix">
            <p>
                <input type="checkbox" id="form-all" value="1" onchange="checkAll(this,'check_user')"/><label
                    for="form-all">全选</label>

                <button class="button" type="button" onclick="deleteUsers()">批量删除</button>
                <a class="button" href="javascript:updateSelectedEmployees()"><span
                        style="background:url(${ctx}/images/img/page_edit.png)" class="icon">&nbsp;</span>修改</a>
                <a class="button" href="#user/user_add.xhtml?organizationId=${organizationId}&t=<%=new Date()%>">
                    <span class="icon" style="background:url(${ctx}/images/img/add.png)">&nbsp;</span>添加</a>
            </p>
        </div>
    </div>
</div>

<script type="text/javascript">
     //员工账号更新
    function updateSelectedEmployees() {
        var checkIds = new Array();
        $("input[type='checkbox'][name='check_user']").each(function() {
            if (this.checked) {
                checkIds.push(this.value);
            }
        });
        if (checkIds.length == 0) {
            //alert("请选择一个人员信息");
            return;
        }

        if (checkIds.length > 1) {
            alert("每次只能更新一个人员信息");
            return;
        }
        var url = "#user/user_edit.xhtml?id=" + checkIds[0];
        window.location.href = url;

    }

     //删除员工账号
    function deleteUsers() {
        var checkIds = new Array();
        $("input[type='checkbox'][name='check_user']").each(function() {
            if (this.checked) {
                checkIds.push(this.value);
            }
        });
        if (checkIds.length == 0) {
            return;
        }
        if (confirm("确定要删除选中的数据吗？删除后将无法恢复!")) {
            doDeleteUsers(checkIds.join(","))
        }
    }

    function doDeleteUsers(ids) {
        var url = "${ctx}/user/user_delete.xhtml";
        $.ajax(url, {
            type: "POST",
            data:{"userIds":ids, "organizationId":"${organizationId}"},
            dataType:"html",
            cache:false,
            success:function(a) {
                var obj = $("#list_content_" + currentTabOrgId);
                obj.html("");
                obj.append(a);
            },
            complete:function() {

            }
        });

    }
</script>